<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 300px;
            height: 300px;
            margin: 50px auto;
        }

        .text {
            margin-top: 20px;
            width: 180px;
            height: 200px;
            background-color: rgb(235, 171, 171);
        }
    </style>
</head>

<body>
    <div class="box">
        <input type="text" placeholder="请输入...">
        <button>发表</button>
        <div class="text"></div>
    </div>

    <script>
     // 获取DOM元素
     const input = document.querySelector('input')
     const button = document.querySelector('button')
     const text = document.querySelector('.text')

     let str = ''
     let arr = /尼玛|操|靠/
     button.onclick = function(){
        str += `<p>${input.value.replace(arr,'**')}</p>`
        text.innerHTML = str
        input.value = ''
     }


    </script>
</body>

</html>